<?php


use Phinx\Migration\AbstractMigration;

class FillOptionsData extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    /**
     * Migrate Up.
     * @throws Exception
     */
    public function up()
    {
        $rows = [
            [
                'name' => 'default_settings',
                'type' => 'system',
                'config' => json_encode([
                    "default_lang" => "zh-cn",
                    "default_nation" => "cn",
                    "default_password" => "Strack@123456",
                    "default_timezone" => "Etc/GMT-8",
                    "default_emailsuffix" => "@strack.com",
                    "default_admin_password" => "Strack@Admin123456",
                    "default_auto_fill_code" => "1"
                ]),
                'uuid' => Webpatser\Uuid\Uuid::generate()->string
            ],
            [
                'name' => 'media_service',
                'type' => 'system',
                'config' => json_encode([
                    "request_url" => 'http://192.168.88.65:19114',
                    "upload_url" => 'http://192.168.88.65:18122/upload/',
                    "access_key" => '86722a27c05c04ce727fe6c1065e3245',
                    "secret_key" => '9f7b06577f066870c2a94e0e11b088b9'
                ]),
                'uuid' => Webpatser\Uuid\Uuid::generate()->string
            ]
        ];

        $this->table('options')->insert($rows)->save();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $this->execute('DELETE FROM options');
    }
}
